package com.zhengshang.web.controller.app;

import com.zhengshang.api.domain.AppGoodsCategory;
import com.zhengshang.api.service.IAppGoodsCategoryService;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.core.page.TableDataInfo;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商品分类Controller
 *
 * @author zhengshang
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/app/goodsCategory")
public class AppGoodsCategoryController extends BaseController {
    @Autowired
    private IAppGoodsCategoryService appGoodsCategoryService;

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('app:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppGoodsCategory appGoodsCategory) {
        startPage();
        List<AppGoodsCategory> list = appGoodsCategoryService.selectAppGoodsCategoryList(appGoodsCategory);
        return getDataTable(list);
    }

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('app:category:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(@RequestParam(required = false)Map params) {
        startPage();
        List<Map> list = appGoodsCategoryService.selectAppGoodsCategoryList1(params);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('app:category:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppGoodsCategory appGoodsCategory) {
        List<AppGoodsCategory> list = appGoodsCategoryService.selectAppGoodsCategoryList(appGoodsCategory);
        ExcelUtil<AppGoodsCategory> util = new ExcelUtil<AppGoodsCategory>(AppGoodsCategory.class);
        return util.exportExcel(list, "category");
    }

    /**
     * 获取商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:category:query')")
    @GetMapping(value = "/{goodsCategoryId}")
    public AjaxResult getInfo(@PathVariable("goodsCategoryId") Long goodsCategoryId) {
        return AjaxResult.success(appGoodsCategoryService.selectAppGoodsCategoryById(goodsCategoryId));
    }

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('app:category:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppGoodsCategory appGoodsCategory) {
        return toAjax(appGoodsCategoryService.insertAppGoodsCategory(appGoodsCategory));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('app:category:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppGoodsCategory appGoodsCategory) {
        return toAjax(appGoodsCategoryService.updateAppGoodsCategory(appGoodsCategory));
    }

    /**
     * 删除商品分类
     */
    @PreAuthorize("@ss.hasPermi('app:category:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{goodsCategoryIds}")
    public AjaxResult remove(@PathVariable Long[] goodsCategoryIds) {
        return toAjax(appGoodsCategoryService.deleteAppGoodsCategoryByIds(goodsCategoryIds));
    }
}
